﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace RotationDemo
{
    // Learn more about making custom code visible in the Xamarin.Forms previewer
    // by visiting https://aka.ms/xamarinforms-previewer
    [DesignTimeVisible(false)]
    public partial class MainPage : ContentPage
    {
        public bool Rotateing { get; set; }
        public MainPage()
        {
            InitializeComponent();
            Rotateing = false;
        }

        async Task RotateImageContinously()
        {
            while (Rotateing) // a CancellationToken in real life ;-)
            {
                for (int i = 1; i < 7; i++)
                {
                    if (rImage.Rotation >= 360f) rImage.Rotation = 0;
                    await rImage.RotateTo(i * (360 / 6), 1000, Easing.Linear);
                }
            }
        }

        private async void TestButton_Clicked(object sender, EventArgs e)
        {
            Rotateing = true;
            await RotateImageContinously();
        }

        private void TestStopButton_Clicked(object sender, EventArgs e)
        {
            Rotateing = false;
        }
    }
}
